package com.ruoyi.system.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ATrain;
import com.ruoyi.system.service.IATrainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训类别Controller
 * 
 * @author ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/system/aTrain")
public class ATrainController extends BaseController
{
    @Autowired
    private IATrainService aTrainService;

    /**
     * 查询培训类别全部列表
     */
    @GetMapping("/trainTypeAll")
    public AjaxResult trainTypeAll(ATrain aTrain)
    {
        return success(aTrainService.selectATrainList(aTrain));
    }

    /**
     * 查询培训类别列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ATrain aTrain)
    {
        startPage();
        List<ATrain> list = aTrainService.selectATrainList(aTrain);
        return getDataTable(list);
    }

    /**
     * 导出培训类别列表
     */
    @Log(title = "培训类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ATrain aTrain)
    {
        List<ATrain> list = aTrainService.selectATrainList(aTrain);
        ExcelUtil<ATrain> util = new ExcelUtil<ATrain>(ATrain.class);
        util.exportExcel(response, list, "培训类别数据");
    }

    /**
     * 获取培训类别详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aTrainService.selectATrainById(id));
    }

    /**
     * 新增培训类别
     */
    @Log(title = "培训类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ATrain aTrain)
    {
        return toAjax(aTrainService.insertATrain(aTrain));
    }

    /**
     * 修改培训类别
     */
    @Log(title = "培训类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ATrain aTrain)
    {
        return toAjax(aTrainService.updateATrain(aTrain));
    }

    /**
     * 删除培训类别
     */
    @Log(title = "培训类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aTrainService.deleteATrainByIds(ids));
    }

    /**
     * 随机6位数字
     */
    @GetMapping("/randomPass")
    public AjaxResult randomPass()
    {
        return success(aTrainService.randomPass());
    }
}
